package com.wanlian.router.ui.main.yun;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.wanlian.router.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Hyu on 2018/10/9.
 * Email: fvaryu@qq.com
 */
public class MoreDialog extends Dialog {
    @BindView(R.id.tv_title)
    TextView tv_title;

    private String title;
    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    public static enum Op {
        down,
        delete,
        rename,
        detail
    }

    public interface OnItemClickListener {
        void onItemClick(Op op);
    }

    public MoreDialog(@NonNull Context context) {
        super(context, R.style.UpgradeDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_more);
        Window window = getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.gravity = Gravity.BOTTOM;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        layoutParams.verticalMargin = 0.f;
        layoutParams.horizontalMargin = 0.f;
        window.setAttributes(layoutParams);

        ButterKnife.bind(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (tv_title != null) {
            tv_title.setText(title);
        }
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @OnClick(R.id.tv_cancel)
    void c() {
        dismiss();
    }

    @OnClick(R.id.tv_rename)
    void rename(){
        dismiss();
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(Op.rename);
        }
    }

    @OnClick(R.id.tv_delete)
    void delete(){
        dismiss();
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(Op.delete);
        }

    }

    @OnClick(R.id.tv_down)
    void down(){
        dismiss();
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(Op.down);
        }
    }

    @OnClick(R.id.tv_detail)
    void detail(){
        dismiss();
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(Op.detail);
        }

    }
}
